<?php

use console\db\channels\TransferMigration;

/**
 * 用户自定义信息缓存表转移
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300000_000008_t_temp_member_detail extends TransferMigration {

    /**
     * @inheritdoc
     */
    public function safeUp() {
        $tempTable = '{{%temp_member_detail}}';
        $sourceTable = '{{%member_detail}}';
        if (!$this->isExistsTable($tempTable)) {
            $columns = parent::getSourceDb()->getTableSchema($sourceTable)->columns;
            $tableColumns = [];
            foreach ($columns as $column) {
                $tableColumns[$column->name] = $column->dbType;
            }
            $this->db->createCommand()->createTable($tempTable, $tableColumns)->execute();
        }
        parent::safeUp();
    }

    /**
     * @inheritdoc
     */
    public function safeDown() {
        $this->dropTable('{{%temp_member_detail}}');
    }

    /**
     * @inheritdoc
     */
    public function getTableOptions() {
        return [
            'temp_member_detail' => [
                'source' => 'member_detail',
                'columns' => [
                    'uid',
                    'gender',
                    'birthday',
                    'sign',
                    'city_id',
                    'inputtime',
                    'updatetime'
                ],
            ]
        ];
    }

}
